package com.yuzhi.common.util.custom;

import cn.dev33.satoken.context.SaHolder;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.yuzhi.common.contant.CacheConstants;
import com.yuzhi.common.contant.CacheNames;
import com.yuzhi.common.util.redis.CacheUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @ClassName: StationUtils
 * @Author: Mario
 * @Date: 2024-08-16 17:10
 * @Description: 测站工具类
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.util.custom
 */
public class StationUtils {

    /**
     * 私有构造参数，防止实例化
     */
    private StationUtils() {

    }

    /**
     * 获取站点名称
     *
     * @param stationCode
     * @return java.lang.String
     * @date: 2024-08-16 17:11:25
     * @author: Mario
     */
    public static String getStationName(String stationCode) {

        // 从缓存中获取站点信息
        return CharSequenceUtil.isNotBlank(CacheUtils.<String>get(CacheNames.STATION_INFO, stationCode)) ? CacheUtils.get(CacheNames.STATION_INFO, stationCode) : "未知站点";

    }

    /**
     * 根据测站编码获取所在灌区名称
     *
     * @param stationCode
     * @return java.lang.String
     * @date: 2024-08-16 17:11:25
     * @author: Mario
     */
    public static String getIrrigationNameByStationCode(String stationCode) {
        // 从缓存中获取站点所在灌区名称
        return CharSequenceUtil.isNotBlank(CacheUtils.<String>get(CacheNames.STATION_KEY, stationCode)) ? CacheUtils.get(CacheNames.STATION_KEY, stationCode) : "未知灌区";
    }

    /**
     * 根据灌区code获取灌区名称
     *
     * @param irrigatedCode
     * @return java.lang.String
     * @date: 2024-9-23
     * @author: Mario
     */
    public static String getIrrigationNameByCode(String irrigatedCode) {
        Map<String, String> map = Optional.ofNullable(CacheUtils.<Map<String, String>>get(CacheNames.IRRIGATED_KEY, CacheNames.IRRIGATED_INFO)).orElse(new HashMap<>(1));
        return map.getOrDefault(irrigatedCode, "灌区不存在");
    }

    /**
     * 根据泵站编码获取泵站名称
     *
     * @param pumpCode
     * @return java.lang.String
     * @date: 2024-11-1
     * @author: Mario
     */
    public static String getPumpName(String pumpCode) {
        // 从缓存中获取泵站信息

        return CharSequenceUtil.isNotBlank(CacheUtils.<String>get(CacheNames.STATION_INFO, pumpCode)) ? CacheUtils.get(CacheNames.STATION_INFO, pumpCode) : "未知泵站";

    }


}
